<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Cache-Control" content="no-siteapp">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=1, minimum-scale=1, maximum-scale=1">
<meta name="renderer" content="webkit">
<meta name="google" value="notranslate">
<meta name="robots" content="index,follow">


<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Akkuman">
<meta name="twitter:description" content="Akkuman的技术博客">
<meta name="twitter:image:src" content="http://127.0.0.1:8000/images/avatar.png">

<meta property="og:url" content="http://127.0.0.1:8000">
<meta property="og:title" content="Akkuman">
<meta property="og:description" content="Akkuman的技术博客">
<meta property="og:site_name" content="Akkuman">
<meta property="og:image" content="http://127.0.0.1:8000/images/avatar.png">
<meta property="og:type" content="website">
<meta name="robots" content="noodp">

<meta itemprop="name" content="Akkuman">
<meta itemprop="description" content="Akkuman的技术博客">
<meta itemprop="image" content="http://127.0.0.1:8000/images/avatar.png">

<link rel="canonical" href="http://127.0.0.1:8000">

<link rel="shortcut icon" href="/favicon.png">
<link rel="apple-itouch-icon" href="/favicon.png">

<link type="text/css" rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="/bundle/css/prism.css">
<link type="text/css" rel="stylesheet" href="/bundle/css/zoom.css">
<link type="text/css" rel="stylesheet" href="/bundle/css/main.css">
<script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>



<script>var cPlayers = [];var cPlayerOptions = [];</script>


<script type="text/javascript">
    var timeSinceLang = {
        year: '年前',
        month: '个月前',
        day: '天前',
        hour: '小时前',
        minute: '分钟前',
        second: '秒前'
    };
    var root = '';
</script>


        <meta name="keywords" content="Linux,">
        <meta name="description" content="lamp服务器被人恶意绑定域名的解决办法">
        <meta name="author" content="Akkuman">
        <title>lamp服务器被人恶意绑定域名的解决办法</title>
    </head>
    <body>
        
        <header id="header" class="clearfix">
  <div class="container-fluid">
      <div class="row">
          <div class="logo">
              <div class="header-logo">
                <script>
                  var getwbclass = function() {
                    var wbclass = ['b', 'w'];
                    return wbclass[Math.floor(Math.random()*wbclass.length)];
                  }
                  var sitetitle = "Akkuman";
                  for (i in sitetitle) {
                    document.write('<a href="/"><span class="' + getwbclass() + ' titlechar">' + sitetitle.charAt(i) + '</span></a>');
                  }          
                  
                </script>
                
                <a id="btn-menu" href="javascript:isMenu();">
                    <span class="b">·</span>
                </a>
                <a href="javascript:isMenu1();">
                    <span id="menu-1" class="bf">1</span>
                </a>
                <a href="javascript:isMenu2();">
                    <span id="menu-2" class="bf">2</span>
                </a>
                <a href="javascript:isMenu3();">
                    <span id="menu-3" class="bf">3</span>
                </a>
              </div>
              <div id="menu-page">
                <a href="/archive.html"><li>归档</li></a>
                <a href="/tag.html"><li>标签</li></a>
                
                <a href="/atom.xml"><li>订阅</li></a>
                
                <a href="about.html"><li>关于</li></a>
              </div>
              <div id="search-box">
                  <div id="search">
                      <input autocomplete="off" type="text" name="s" id="menu-search" placeholder="搜索..." data-root="" />
                  </div>
              </div>
          </div>
      </div>
  </div>
  </header>
        <div id="body" class="clearfix">
            <div class="container-fluid">
                <div class="row">
                    <div id="main" class="col-12 clearfix" role="main">
                        <article class="posti" itemscope itemtype="http://schema.org/BlogPosting">
                            <h1 class="post-title" itemprop="name headline">lamp服务器被人恶意绑定域名的解决办法</h1>
                            <div class="post-meta">
                                <p>
                                    Written by <a itemprop="name" href="/about.me.html" rel="author">Akkuman</a> with ♥ on <time datetime="1464444542" itemprop="datePublished"></time> in <a href="/tag/Linux/index.html">Linux </a>
                                </p>
                            </div>
                            <div class="post-content" itemprop="articleBody">
                                <h1>还没开始就被别人绑定了域名</h1>

<h2>事情的起因与发现</h2>

<p>刚买了个服务器搭建了一个dz，想着域名还没备案，就先搭建了起来，然后在做DDOS测试时偶然发现服务器被别人恶意把域名绑定了</p>

<h2>最初的解决方案</h2>

<p>没管。。。。。。
后来发现有影响，朋友也一直给我说叫我整下</p>

<h2>利用重定向把恶意指向过来的域名指到别处</h2>

<p>要利用301重定向，首先我们要在Apache上配置一下，Apache默认是不开启.htaccess的</p>

<hr />

<h3>0x01.编辑httpd.conf文件</h3>

<p>打开/etc/httpd/conf目录下的httpd.conf文件，找到这一行：</p>

<pre><code class="language-bash">LoadModule rewrite_module modules/mod_rewrite.so
</code></pre>

<blockquote>
<p>当然，你得确定你的/etc/httpd/modules下有mod_rewrite.so这个文件</p>

<pre><code class="language-bash">&gt; ls /etc/httpd/modules | grep mod_rewrite
&gt; ```
如果你没有找到这一行，记得在httpd.conf文件里直接添加这一行


----------


### 0x02.设置AllowOverride

同样的在httpd.conf文件中找到：
```bash
&lt;Directory &quot;/var/www/html&quot;&gt;
    #
    # Possible values for the Options directive are &quot;None&quot;, &quot;All&quot;,
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that &quot;MultiViews&quot; must be named *explicitly* --- &quot;Options All&quot;
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be &quot;All&quot;, &quot;None&quot;, or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
&lt;/Directory&gt;
</code></pre>

<p>或者它长这个样子：</p>

<pre><code class="language-bash">&lt;Directory /&gt;
Options FollowSymLinks
AllowOverride None
&lt;/Directory&gt;
</code></pre>

<p>什么，你告诉我还是找不到？？？
那教你一个办法
锁定关键词<code>FollowSymLinks</code>和<code>AllowOverride None</code></p>

<p>vi的向下查找命令是<code>:/你要查找的</code>
vi的向上查找命令是<code>:?你要查找的</code>
n是下一个
N是上一个</p>
</blockquote>

<p>相信你已经找到了
接下来把<code>None</code>改成<code>All</code></p>

<hr />

<h3>0x03.编写规则文件.htaccess</h3>

<p>跑去网站根目录下，比如我的是/var/www/html
如果存在.htaccess，忽略下一步，直接打开编辑
然后新建.htaccess文件<code>touch .htaccess</code>
编辑.htaccess文件<code>vi .htaccess</code>
添加如下规则</p>

<pre><code class="language-bash">RewriteEngine on
RewriteCond %{HTTP_HOST} ^别人的域名.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.别人的域名.com$
RewriteRule ^(.*)$ http://www.自己的域名.com/$1 [R=301,L]
</code></pre>

<hr />

<h1>个人的修改</h1>

<p>我知道，你在网上所找到的方法都是上面那种代码，并且应该都没有提 教你怎么开启.htaccess
<img src="" data-src="http://7xusrl.com1.z0.glb.clouddn.com/%E6%9A%B4%E6%BC%AB%E5%8E%BB%E4%BB%96%E7%88%B9%E7%9A%84%E9%80%BB%E8%BE%91.jpg" alt="去他爹的" />
但是本人实验过，这配置进去还有问题，设置重启Apache后，访问网站提示500错误
<img src="" data-src="http://7xusrl.com1.z0.glb.clouddn.com/500error.png" alt="500error" />
机智的我总要查看日志啊</p>

<pre><code class="language-bash">cat /var/log/messages | grep httpd
</code></pre>

<p>找到了错误
<img src="" data-src="http://7xusrl.com1.z0.glb.clouddn.com/QQ%E5%9B%BE%E7%89%8720160528214617.png" alt="httpderror" />
英语不太好，但是大致知道是服务器没有限定域名，需要修改ServerName,而ServerName字段值在httpd.conf中是被注释掉的
我们在httpd.conf修改它</p>

<pre><code class="language-bash">#ServerName: www.example.com:80
</code></pre>

<p>改为</p>

<pre><code class="language-bash">ServerName: 115.**.**.57:80
</code></pre>

<p>然后重启Apache，可以访问了</p>

<hr />

<h1>后续</h1>

<p>好的故事都会有后续的</p>

<p>以为这样就万事大吉了?</p>

<p>但是我这个被坑得不轻
admin.xx.com都被他解析到我服务器上来了</p>

<p>老衲怎么破
<img src="" data-src="http://7xusrl.com1.z0.glb.clouddn.com/%E6%9A%B4%E6%BC%AB%E6%88%90%E9%BE%99.jpg" alt="成龙挠头" />
.htaccess好像可以用正则表达式，一查，果然
那就改一下.htaccess咯
<img src="" data-src="http://7xusrl.com1.z0.glb.clouddn.com/%E6%9A%B4%E6%BC%AB%E5%82%BB%E7%AC%91.jpg" alt="shaxiao" /></p>

<pre><code class="language-bash">RewriteEngine on
RewriteCond %{HTTP_HOST} ^别人的域名.com$ [OR]
RewriteCond %{HTTP_HOST} ^.*.别人的域名.com$
RewriteRule ^(.*)$ http://www.自己的域名.com/$1 [R=301,L]
</code></pre>

<p>机智的你已经发现第三行中的www被我改成了.*，就是匹配0个或者多个字符，当然*你可以改成+</p>

<p>然后重启Apache</p>

<pre><code class="language-bash">systemctl restart httpd
</code></pre>

<p>或者</p>

<pre><code class="language-bash">service httpd restart
</code></pre>

<p>现在我再访问。。。嘿嘿嘿，被我跳转到百度了
<img src="" data-src="http://7xusrl.com1.z0.glb.clouddn.com/%E6%9A%B4%E6%BC%AB%E5%98%BF%E5%98%BF%E5%98%BF.jpeg" alt="heihei" /></p>

<hr />

<h2>思考</h2>

<p>当然，还有其他的方法，自己也可以去网上找找
对了，那个刚才在httpd.conf里换ip的地方也可换自己的域名，因为我的还在备案，就没改</p>

                            </div>
                            <div style="display:block;" class="clearfix">
                                <section style="float:left;">
                                    <span itemprop="keywords" class="tags">
                                        tag(s): <a href="/tag/Linux/index.html">Linux </a>
                                    </span>
                                </section>
                                <section style="float:right;">
                                    <span><a id="btn-comments" href="javascript:isComments();">show comments</a></span> · <span><a href="javascript:goBack();">back</a></span> · 
                                    <span><a href="/">home</a></span>
                                </section>
                            </div>
                            



<div id="comments" class="gen">
    <script>
        document.write('<section id="disqus_thread"></section>');
        var site_comment_load = function disqus() {
            var d = document, s = d.createElement('script');
            s.src = '//Akkum4n.disqus.com/embed.js';
            s.setAttribute('data-timestamp', +new Date());
            (d.head || d.body).appendChild(s);
        }
    </script>
</div>

                        </article>
                    </div>
                </div>
            </div>
        </div>
        <footer id="footer" role="contentinfo">
    <div class="container-fluid">
        <div class="row">
        <div class="col-12">
            &copy; 
            <script type="text/javascript">
                document.write(new Date().getFullYear());
            </script>
            <a href="/">Akkuman</a>.
            Using <a target="_blank" href="http://www.chole.io/">Ink</a> & <a target="_blank" href="/">Story</a>.
        </div>
        </div>
    </div>
</footer>

<script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<script src="/bundle/js/prism.js"></script>
<script src="/bundle/js/zoom-vanilla.min.js"></script>
<script src="/bundle/js/main.js"></script>

<script>
    window.onload=function(){
        if (window.location.hash!='') {
          var i=window.location.hash.indexOf('#comment');
          var ii=window.location.hash.indexOf('#respond-post');
          if (i != '-1' || ii != '-1') {
            document.getElementById('btn-comments').innerText='hide comments';
            document.getElementById('comments').style.display='block';
          }
        }
    }

    function isMenu(){
        if(document.getElementById('menu-1').style.display=='inline'||document.getElementById('menu-1').style.display=='block'){
            $('#search-box').fadeOut(200);
            $('#menu-page').fadeOut(200);
            $('#menu-1').fadeOut(500);
            $('#menu-2').fadeOut(400);
            $('#menu-3').fadeOut(300);
        } else {
            $('#menu-1').fadeIn(150);
            $('#menu-2').fadeIn(150);
            $('#menu-3').fadeIn(150);
        }
    }

    function isMenu1(){
        if(document.getElementById('menu-page').style.display=='block'){
            $('#menu-page').fadeOut(300);
        } else {
            $('#menu-page').fadeIn(300);
        }
    }

    function isMenu2(){
        if(document.getElementById('torTree')){
            if(document.getElementById('torTree').style.display=='block'){
                $('#torTree').fadeOut(300);
            } else {
                $('#torTree').fadeIn(300);
            }
        }
    }

    function isMenu3(){
        if(document.getElementById('search-box').style.display=='block'){
            $('#search-box').fadeOut(300);
        } else {
            $('#search-box').fadeIn(300);
        }
    }

    function isComments(){
        if(document.getElementById('btn-comments').innerText=='show comments'){
            document.getElementById('btn-comments').innerText='hide comments';
            document.getElementById('comments').style.display='block';
            site_comment_load();
        } else {
            document.getElementById('btn-comments').innerText='show comments';
            document.getElementById('comments').style.display='none';
        }
    }

    function Search404(){
        $('#menu-1').fadeIn(150);
        $('#menu-2').fadeIn(150);
        $('#menu-3').fadeIn(150);
        $('#search-box').fadeIn(300);
    }

    function goBack(){
        window.history.back();
    }
</script>


<script async>
"use strict";
(function(){
var cp = function(){
    var len = cPlayerOptions.length;
    for(var i=0;i<len;i++){
        var element = document.getElementById('player' + cPlayerOptions[i]['id'])
        while (element.hasChildNodes()) {
            element.removeChild(element.firstChild);
        };
        cPlayers[i] = new cPlayer({
            element: element,
            list: cPlayerOptions[i]['list'],
            });
    };
    cPlayers = [];cPlayerOptions = [];
};
var script = document.createElement('script');
script.type = "text/javascript";
script.src = "https://cdn.bootcss.com/cplayer/3.2.1/cplayer.js";
script.async = true;
if(script.readyState){  
    script.onreadystatechange = function(){
        if (script.readyState == "loaded" ||
            script.readyState == "complete"){
            script.onreadystatechange = null;
            cp();
        }
    };
}else{  
    script.onload = function(){
        cp();
    };
}
document.head.appendChild(script);
})();
</script>

    </body>
</html>
